package com.hankol.winecellar.adapter

import android.content.Context
import android.os.Bundle
import android.widget.ImageView
import com.baselibrary.Constants
import com.baselibrary.extension.checkNotNull
import com.baselibrary.extension.checkValue
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.TimeUtil
import com.baselibrary.view.VipHeardImgView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.MultiTransformation
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.winecellar.R
import com.hankol.winecellar.bean.WineryEvaluateListBean
import com.baselibrary.view.PhotosContentView
import com.baselibrary.view.PhotosContentViewAdapter
import java.util.*

/*评论管理列表
* */
class CommonManageAdapter : BaseQuickAdapter<WineryEvaluateListBean, BaseViewHolder>(R.layout.item_common_manage) {

    override fun convert(helper: BaseViewHolder, item: WineryEvaluateListBean) {
        helper.setText(R.id.tv_name, item.name.checkValue()).setText(R.id.tv_time, TimeUtil.fromToday(item.ctime))
        val heardImg = helper.getView<VipHeardImgView>(R.id.civ_cover)
        item.let {
            heardImg.setData(it.icon.checkValue(), it.isFans == 1);
        }
        helper.setText(R.id.tv_content,item.wineryCommentDesc.checkValue())
        val nineGridPhoto = helper.getView<PhotosContentView<String>>(R.id.photo_content_view)
        nineGridPhoto.setAdapter(object : PhotosContentViewAdapter<String>() {
            override fun onDisplayImage(context: Context, imageView: ImageView, data: String) {
                Glide.with(context)
                        .load(data).placeholder(R.drawable.icon_def_loading).error(R.drawable.icon_def_loading)
                        .apply(RequestOptions().transform(MultiTransformation(CenterCrop(), RoundedCorners(12))))
                        .into(imageView)
            }

            override fun onItemImageClick(context: Context, imageView: ImageView, index: Int, list: MutableList<String>) {
                super.onItemImageClick(context, imageView, index, list)
                //图片详情
                val bundle = Bundle()
                bundle.putStringArrayList(Constants.KEY_URLS, list as ArrayList<String>)
                bundle.putInt(Constants.KEY_INDEX, index)
                bundle.putStringArrayList(Constants.KEY_COMMENT_CONTENT, arrayListOf(item.wineryCommentDesc))
                bundle.putStringArrayList(Constants.KEY_COMMENT_TITLE, arrayListOf())
                ActivityRouter.startActivity(ActivityRouter.WINE_CELLAR.IMG_VIDEO_DETAIL,bundle)
            }
        })
        if (item.wineryCommentImg.checkNotNull()) {
            nineGridPhoto.setImageData(item.wineryCommentImg.split(",").toMutableList())
        }
        helper.addOnClickListener(R.id.img_edit)
        helper.addOnClickListener(R.id.img_del)
        helper.addOnClickListener(R.id.civ_cover)
        helper.addOnClickListener(R.id.tv_name)
    }
}